package wviz.index;

import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;

/**
 * @author Hadi
 *         Date: 08-Dec-2008
 *         Time: 18:13:35
 * wraps the positions of a term; this class is motivated by lucene's corresponding class
 */
public  class Positions {
	
	//Map map = Collections.synchronizedMap(hashMap);

    private Map<Integer/*docId*/, int[]/*positions*/> docId_positionsMap = Collections.synchronizedMap(
    	new HashMap<Integer, int[]>());

    public int[] getPositions(int docId){
       return docId_positionsMap.get(docId);
    }

    public Set<Integer> getDocIds(){
        return docId_positionsMap.keySet();
    }

    public synchronized void add(Integer docId, int[] positions){
 //  	docId_positionsMap.put(docId, positions);
    	if (docId_positionsMap.put(docId, positions) != null)
        throw new RuntimeException("positions are already assigned to this docId");
    }

}
